<?php

// the usual include
// include("mysql_conn.php");
include("basepath.php");

// get sub directory if one exists
$dir=$_GET["dir"];
$msg=$_GET["msg"];

clearstatcache();

// combine the two to get the full path without it being in the URL
// basepath is the filesystem directory
$fullpath="$basepath" . "$dir";
// webpath is the web server path
$fullwebpath="$webpath" . "$dir";
//determine previous directory if applicable
$dirarray=explode("/",$dir);
array_pop($dirarray);
array_shift($dirarray);
function add_slash($i1,$i2)
{
 return $i1 ."/" . $i2;
}
$prevdir=array_reduce($dirarray,"add_slash");

echo "<html>
 <head>
 <title>PHP File Manager</title>
 <link rel='stylesheet' type='text/css' href='style.css'>
 </head>
 <body>
 <h2>PHP File Manager</h2>
 <p>Current path: $fullwebpath</p>";

// for debugging only
// echo "Full Path: $fullpath<br>";
// echo "dir: " . $dir . "<br>";
// print_r($dirarray);
// echo "<br>";
// echo "prevdir:" . $prevdir . "<br>";

// now, let's do something! 

echo "<p id='tiny'>Click to view/download the files";
echo " | <a href='$refreshurl?dir=$prevdir'>Go up a level</a></p>";

echo "<table width=50%><tr><th>Filename</th><th>Size (MB)</th><th>Last Changed</th><th>Actions</th></tr>";

//get a listing of the directory
$files=scandir($fullpath,0);

//output it
while ($file=current($files))
{
 // get rid of the . and ..
 if(($file != '.') && ($file != '..') && ($file != '.htaccess'))
 {
  if (is_dir("$fullpath/$file"))
  {
  echo "<tr><td><a href='$refreshurl?dir=$dir/$file'>" . $file . "/</a></td>";
  }
  else
  {
  echo "<tr><td><a href='$fullwebpath/$file'>" . $file . "</a></td>";
  }
  echo "<td>" . round((filesize("$fullpath/$file"))/(1024*1024),3) . "</a></td>";
  echo "<td>" . date('M jS Y g:ia', filemtime("$fullpath/$file")) . "</td>";
  if (is_dir("$fullpath/$file"))
  {
  // $dir="$dir" . "$file";
  echo "<td id='tiny'><a href='deletefile.php?file=" . $file . "&dir=" . "$dir" . "'>Delete</a></td></tr>";
  }
  else
  {
  echo "<td id='tiny'><a href='$fullwebpath/$file'>View/Download</a> | <a href='deletefile.php?file=" . $file . "&dir=" . "$dir" . "'>Delete</a></td></tr>";
  }
 }
 next($files);
}

echo "</table><p><table width=50%><tr><td><form action='upload.php?dir=$dir' method='post' enctype='multipart/form-data'>Upload files: </td><td><input type='file' name='file[]' id='file' multiple><input type='submit' name='Submit' value='Upload'> (max size 8MB per file)</form></td></tr>";
echo "<tr><td><form action='mkdir-do.php?dir=$dir' method='post' enctype='multipart/form-data'>New folder: </td><td><input type='text' name='name' size='40'><input type='submit' name='Submit' value='Create'></form></td></tr>";
echo "<tr><td>Message: </td><td> " . $msg . "</td></tr></table>";
echo "</body></html>";
?>





